package desktop.local.single;

import pulpcore.Stage;
import pulpcore.scene.Scene2D;
import desktop.conf.key.KeyConfDefault;
import desktop.core.bar.BarController;
import desktop.core.playfield.PlayFieldModel;
import desktop.core.playfield.PlayFieldViewSingleBar;
import desktop.playerguide.scoreForm.ScoreGroup;
import desktop.playerguide.toolbar.ToolBar;

public class LocalSingleScene extends Scene2D {

	private PlayFieldViewSingleBar playFieldView;
	private NextBarView nextBarView;
	private ScoreGroup scoreForm;
	private ToolBar toolBar;

	@Override
	public void load() {

		playFieldView = new PlayFieldViewSingleBar(0, 0,
				Stage.getWidth() * 3 / 4, Stage.getHeight(),
				new PlayFieldModel(), new BarController(new KeyConfDefault()));
		this.add(playFieldView);

		nextBarView = new NextBarView(Stage.getWidth() * 3 / 4, 0, Stage
				.getWidth() / 4, Stage.getHeight() / 3, playFieldView
				.getNextBar());
		this.add(nextBarView);
		scoreForm = new ScoreGroup();
		scoreForm.setLocation(Stage.getWidth() * 0.5, 0);
		this.add(scoreForm);
		toolBar = new ToolBar(Stage.getWidth() * 3 / 4, Stage.getHeight() / 3,
				Stage.getWidth() / 4, Stage.getHeight() * 2 / 3);
		this.add(toolBar);
	}

	@Override
	public void update(int elapsedTime) {
		nextBarView.loadNextBar(playFieldView.getNextBar());
		scoreForm.setScore(playFieldView.getPointsTotally());
		if (toolBar.isTortoiseCardClicked()) {
			this.playFieldView.slowDown();
			toolBar.tortoiseCardClickedPerformed();
		}
	}

}